<template>
  <div id="screenfull">
    <svg-icon
      :name="isFullscreen ? 'exit-fullscreen' : 'fullscreen'"
      @click="click"
    />
  </div>
</template>

<script lang="ts">
import screenfull from 'screenfull'
import { Component, Vue, Watch } from 'vue-property-decorator'

const sf = screenfull

@Component({
  name: 'Screenfull'
})
export default class extends Vue {
  private isFullscreen = false // 存储状态

  @Watch('isFullscreen')
  onFullscreenChange(val: boolean) {
    this.$message.info((val ? '进入' : '退出') + '全屏')
  }

  private click() {
    if (!sf.isEnabled) return this.$message.warning('该窗口不支持全屏')
    this.isFullscreen = !this.isFullscreen
    sf.toggle()
  }
}
</script>
